package com.suntront.module_arcgis.arcgis

import com.esri.arcgisruntime.geometry.PointCollection
import com.esri.arcgisruntime.geometry.SpatialReferences
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay
import com.esri.arcgisruntime.mapping.view.LocationDisplay
import com.mtjsoft.www.kotlinmvputils.base.BaseViewModel
import com.mtjsoft.www.kotlinmvputils.event.SingleLiveEvent

class ArcGisViewModel : BaseViewModel() {

    private val drowType: SingleLiveEvent<Int> = SingleLiveEvent()

    // 点集合
    private var mPointCollection: SingleLiveEvent<PointCollection>? = null
    private var mGraphicsOverlay: SingleLiveEvent<GraphicsOverlay>? = null

    // 定位
    private var mLocationDisplay: SingleLiveEvent<LocationDisplay>? = null

    fun getGraphicsOverlay(): SingleLiveEvent<GraphicsOverlay> {
        if (mGraphicsOverlay == null) {
            mGraphicsOverlay = SingleLiveEvent()
            mGraphicsOverlay!!.value = GraphicsOverlay()
        }
        return mGraphicsOverlay!!
    }

    fun getPointCollection(): SingleLiveEvent<PointCollection> {
        if (mPointCollection == null) {
            mPointCollection = SingleLiveEvent()
            mPointCollection!!.value = PointCollection(SpatialReferences.getWebMercator())
        }
        return mPointCollection!!
    }

    fun getDrowType(): SingleLiveEvent<Int> = drowType

    fun setDrowType(i: Int) {
        getDrowType().postValue(i)
    }

    fun getLocationDisplay(): SingleLiveEvent<LocationDisplay> {
        if (mLocationDisplay == null) {
            mLocationDisplay = SingleLiveEvent()
        }
        return mLocationDisplay!!
    }

    fun setLocationDisplay(locationDisplay: LocationDisplay) {
        getLocationDisplay().value = locationDisplay
    }
}